package com.servlet;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Random;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.google.gson.Gson;

/**
 * Servlet implementation class HelloAction
 */
public class HelloServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public HelloServlet() {
        super();
        // TODO Auto-generated constructor stub
    }
    
	@Override
	protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		resp.setContentType("text/html; charset=UTF-8");
		PrintWriter out = resp.getWriter();
		List<Map<String,String>> l= new ArrayList<Map<String,String>>();
		Random r = new Random();
		String[] c = { "0", "1", "2", "3", "4", "5", "6", "7", "8", "9",
				"a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l",
				"m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x",
				"y", "z", "A", "B", "C", "D", "E", "F", "G", "H", "I", "J",
				"K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V",
				"W", "X", "Y", "Z" };
		String type[] = {"user-name", "email", "mobile-number", "qq", "address", "domain", "social-worker", "Nmap",
				"whois", "IP", "other" };
		int o=r.nextInt(10)+5;
		for (int p = 0; p < o; p++) {
			int n = r.nextInt(5)+3;//产生一个[3,8]之间的字符串
			String str = "";
			for (int i = 0; i < n; i++) {
				str +=c[r.nextInt(c.length)];
			}
			Map<String,String> map= new HashMap<String, String>();
			map.put("source", req.getParameter("name"));
			map.put("target", str);
			map.put("types", type[r.nextInt(type.length)]+"");
			l.add(map);
		
		}
		System.out.println(l);
		out.print(new Gson().toJson(l));
		out.flush();
		out.close();
	}
	
	

}
